package com.project.common.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.parameters.HeaderParameter;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DocConfig {
    @Bean
    public GroupedOpenApi groupedOpenApi() {
        String[] paths = {"/**"};
        String[] packagedToMatch = {"com.project"};
        return GroupedOpenApi.builder().group("XX网")
                .pathsToMatch(paths)
                .addOperationCustomizer((operation, handlerMethod) -> operation.addParametersItem(new HeaderParameter().name("groupCode")
                        .example("测试")
                        .description("实现类")
                        .schema(new StringSchema()._default("BR").name("Authorization").description("登录token"))))
                .packagesToScan(packagedToMatch).build();
    }

    @Bean
    public OpenAPI customOpenApi() {
        return new OpenAPI()
                .info(new Info()
                        .summary("XX网")
                        .contact(new Contact().name("impls").url("http://127.0.0.1").email("机密"))
                        .title("系统模块API")
                        .version("1.0.0")
                        .description("系统基础相关功能")
                        .termsOfService("https://www.bcd.ren")
                        .license(new License().name("impls")
                                .url("https://www.bcd.ren")));
    }

}
